using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Data.SqlClient;


using Material.Object;
using Material.DAL;
namespace Material.Entity
{
	public class TblTransPenjBarangHDREntity
	{
		private Accessor accessor;
		private string connString;

		public TblTransPenjBarangHDREntity (string _connString)
		{
			 this.connString = _connString;
		}

		public int Insert(TblTransPenjBarangHDR tbltranspenjbaranghdr)
		{
			 int result = -1;
			 accessor = new Accessor(true, connString);
			 accessor.CommandText = "TblTransPenjBarangHDR_Insert";
			 accessor.CommandType = CommandType.StoredProcedure;
			 accessor.Add("@IdTransHDR" ,tbltranspenjbaranghdr.IdTransHDR );
			 accessor.Add("@TglJual" ,tbltranspenjbaranghdr.TglJual );
			 accessor.Add("@CreatedDate" ,tbltranspenjbaranghdr.CreatedDate );
			 accessor.Add("@CreatedBy" ,tbltranspenjbaranghdr.CreatedBy );
			 accessor.Add("@ModifiedDate" ,tbltranspenjbaranghdr.ModifiedDate );
			 accessor.Add("@ModifiedBy" ,tbltranspenjbaranghdr.ModifiedBy );

			 result = Excutor.ExecuteNonQuery(accessor);
			 if (result != -1)
				 accessor.CommitTransaction();
			 else
				 accessor.RollBackTransaction();
			 return result;
		}

		public int Update(TblTransPenjBarangHDR tbltranspenjbaranghdr)
		{
			 int result = -1;
			 accessor = new Accessor(true, connString);
			 accessor.CommandText = "TblTransPenjBarangHDR_Update";
			 accessor.CommandType = CommandType.StoredProcedure;
			 accessor.Add(@"IdTransHDR" ,tbltranspenjbaranghdr.IdTransHDR );
			 accessor.Add(@"TglJual" ,tbltranspenjbaranghdr.TglJual );
			 accessor.Add(@"CreatedDate" ,tbltranspenjbaranghdr.CreatedDate );
			 accessor.Add(@"CreatedBy" ,tbltranspenjbaranghdr.CreatedBy );
			 accessor.Add(@"ModifiedDate" ,tbltranspenjbaranghdr.ModifiedDate );
			 accessor.Add(@"ModifiedBy" ,tbltranspenjbaranghdr.ModifiedBy );

			 result = Excutor.ExecuteNonQuery(accessor);
			 if (result != -1)
				 accessor.CommitTransaction();
			 else
				 accessor.RollBackTransaction();
			 return result;
		}

		public int Delete(TblTransPenjBarangHDR tbltranspenjbaranghdr)
		{
			 int result = -1;
			 accessor = new Accessor(true, connString);
			 accessor.CommandText = "TblTransPenjBarangHDR_Delete";
			 accessor.CommandType = CommandType.StoredProcedure;
			 accessor.Add(@"IdTransHDR" ,tbltranspenjbaranghdr.IdTransHDR);

			 result = Excutor.ExecuteNonQuery(accessor);
			 if (result != -1)
				 accessor.CommitTransaction();
			 else
				 accessor.RollBackTransaction();
			 return result;
		}

		public TblTransPenjBarangHDR GetDataByID(TblTransPenjBarangHDR tbltranspenjbaranghdr)
		{
			 TblTransPenjBarangHDR result = new TblTransPenjBarangHDR();
			 accessor = new Accessor(true, connString);
			 accessor.CommandText = "TblTransPenjBarangHDR_SelectByID";
			 accessor.CommandType = CommandType.StoredProcedure;
			 accessor.Add(@"IdTransHDR" ,tbltranspenjbaranghdr.IdTransHDR);

			 SqlDataReader rdr = Excutor.GetDataReader(accessor);
			 if (rdr.HasRows)
			 {
				 while (rdr.Read())
					 {
						 result.IdTransHDR = rdr.GetInt32(0);
						 result.TglJual = rdr.GetDateTime(1);
						 result.CreatedDate = rdr.GetDateTime(2);
						 result.CreatedBy = rdr.GetString(3);
						 result.ModifiedDate = rdr.GetDateTime(4);
						 result.ModifiedBy = rdr.GetString(5);
					  }
			}
			 return result;
		}

		public List<TblTransPenjBarangHDR> GetDataAll()
		{
			 List<TblTransPenjBarangHDR> result = new List<TblTransPenjBarangHDR>();
			 accessor = new Accessor(true, connString);
			 accessor.CommandText = "TblTransPenjBarangHDR_SelectAll";
			 accessor.CommandType = CommandType.StoredProcedure;

			 SqlDataReader rdr = Excutor.GetDataReader(accessor);
			 if (rdr.HasRows)
			 {
				 while (rdr.Read())
					 {
						 TblTransPenjBarangHDR obj = new TblTransPenjBarangHDR();
						 obj.IdTransHDR = rdr.GetInt32(0);
						 obj.TglJual = rdr.GetDateTime(1);
						 obj.CreatedDate = rdr.GetDateTime(2);
						 obj.CreatedBy = rdr.GetString(3);
						 obj.ModifiedDate = rdr.GetDateTime(4);
						 obj.ModifiedBy = rdr.GetString(5);
						 result.Add(obj);
					  }
			}
			 return result;
		}

	}
}
